﻿using Microsoft.VisualStudio.CommandBars;
using System;
using System.Runtime.CompilerServices;
using EnvDTE;
using EnvDTE80;

namespace MoXAML.Infrastructure
{
    public static class MoXamlUtility
    {
        public static CommandBarPopup BuildPopup(this CommandBar parent, string barName)
        {
            CommandBarPopup popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup,
                RuntimeHelpers.GetObjectValue(Type.Missing), RuntimeHelpers.GetObjectValue(Type.Missing), 1, true);
            popup.CommandBar.Name = barName;
            popup.Caption = "MoXAML Power Toys";
            return popup;
        }
        public static CommandBarPopup BuildPopup(this CommandBar parent, string barName, int position)
        {
            CommandBarPopup popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup,
                RuntimeHelpers.GetObjectValue(Type.Missing), RuntimeHelpers.GetObjectValue(Type.Missing), position, true);
            popup.CommandBar.Name = barName;
            popup.Caption = "MoXAML Power Toys";
            return popup;
        }
        public static CommandBarPopup BuildPopup(this CommandBar parent, string barName, string caption, int position)
        {
            CommandBarPopup popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup,
                RuntimeHelpers.GetObjectValue(Type.Missing), RuntimeHelpers.GetObjectValue(Type.Missing), position, true);
            popup.CommandBar.Name = barName;
            popup.Caption = caption;
            return popup;
        }
        public static CommandBarPopup BuildPopup(this CommandBarPopup parent, string barName, string caption)
        {
            CommandBarPopup popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup,
                RuntimeHelpers.GetObjectValue(Type.Missing), RuntimeHelpers.GetObjectValue(Type.Missing), parent.Controls.Count + 1, true);
            popup.CommandBar.Name = barName;
            popup.Caption = caption;
            return popup;
        }

        public static TextSelection TextSelection(this DTE2 application)
        {
            return application.ActiveDocument.Selection as TextSelection;
        }

    }
}
